<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增题库')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-qu-imp">
        	<div class="form-group">	
				<label class="col-sm-3 control-label is-required">题库：</label>
	            <div class="col-sm-8">
	                <select name="repoId" id="repoId" class="form-control">
						<option th:each="data : ${repoList}" th:selected="${repoId == data.id}" th:text="${data.title}" th:value="${data.id}"></option>
					</select>
	            </div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label is-required">文件：</label>
	            <div class="col-sm-8">
	                <input id="file" name="file" type="file" >
	                </br>
	                <font color='red' class="pull-left">
	                	提示：仅允许导入"xlsx"格式文件！附件最大10M！
	                	</br></br>
	                	导入模板：
	                	<a href="/ruoyi/tmpl/quTmpl.xlsx" class="btn btn-default btn-xs">
	                		<i class="fa fa-file-excel-o"></i>下载模版
	                	</a>
	                </font>
	            </div>
			</div>
		</form>
	</div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "exam/qu";
        $("#form-qu-imp").validate({
        	onkeyup: false,
        	rules:{
        		repoId:{
					required: true,
				},
				file:{
        			required : true
        		}
        	},
        	focusCleanup: true
        })
        function submitHandler() {
        	if ($.validate.form()) {
        		 var file = $("#file").val();
        		 if(file != '' && !$.common.endWith(file, '.xlsx')){
        			 $.modal.msgWarning("请选择后缀为xlsx的文件");
        			 return false;
        		 }
        		 if(file != ''){
        			 var size = $('#file')[0].files[0].size;
        			 var maxSize=10*1024*1024;
        			 if(size >= maxSize){
        				 $.modal.msgWarning("上传文件超过规定大小！");
            			 return false;
        			 }
        		 }
        		 var formData = new FormData();
        		 formData.append("repoId", $("#repoId").val());
        		 formData.append("file", $("#file")[0].files[0]);
        		 $.ajax({
        			 type:"POST",
        			 url:prefix+"/importData",
        			 data:formData,
        			 contentType:false,
        			 processData:false,
        			 beforeSend:function(){
        				 $.modal.loading("正在处理中，请稍后...");
        				 $.modal.disable();
        			 },
        		 	 success:function(result){
        		 		 $.operate.successCallback(result);
        		 	 }
        		 })
        		 
        	}
        }
	</script>
</body>
</html>
